package com.bw.jigou.controller;

import com.bw.autoconfig.UploadService;
import com.bw.jigou.domain.Jigou;
import com.bw.jigou.service.JigouService;
import com.bw.jigou.units.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

@RestController
@RequestMapping("/jigou")
@RefreshScope
public class JigouController {
    @Autowired
    private JigouService jigouService;
    @Value("${spring.test}")
    private String test;
    @RequestMapping("/test")
    public String test(){
        return test;
    }
    @Autowired
    private UploadService uploadService;
    @RequestMapping("/list")
    public List<String[]> list(){
        List<String[]> exchart = jigouService.exchart();
        return exchart;
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Jigou jigou){
        boolean save = jigouService.save(jigou);
        return save?Result.success():Result.fail();
    }
    @RequestMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        String s = uploadService.addPic(file);
        return Result.success(s);
    }

}
